package com.atguigu;

import org.apache.http.HttpHost;
import org.elasticsearch.client.*;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.indices.CreateIndexResponse;

import java.io.IOException;

/**
 * create by undeRdoG on  2021-06-20  17:31
 * 凡心所向，素履以往，生如逆旅，一苇以航。
 */
public class ESTest_Client_Create {
    public static void main(String[] args) throws IOException {

        //  创建ES 客户端
        RestHighLevelClient esClient = new RestHighLevelClient(
                RestClient.builder(new HttpHost("localhost",9200))
        );

        // 创建索引
        CreateIndexRequest request = new CreateIndexRequest("user");
        CreateIndexResponse createIndexResponse = esClient.indices().create(request, RequestOptions.DEFAULT);

        // 响应状态
        boolean responseAcknowledged = createIndexResponse.isAcknowledged();
        System.out.println(responseAcknowledged);

        // 关闭es客户端
        esClient.close();

    }
}
